Banco de Dados

O banco de dados “Mental Health Diagnosis and Treatment Monitoring” foi obtido na plataforma Kaggle e contém as observações de 500 pacientes acerca de diagnósticos em saúde mental, planos de tratamento e desfechos, além de outras informações.

O banco contém as seguintes variáveis:

names(dados)
##  [1] "Patient.ID"                   "Age"                         
##  [3] "Gender"                       "Diagnosis"                   
##  [5] "Symptom.Severity..1.10."      "Mood.Score..1.10."           
##  [7] "Sleep.Quality..1.10."         "Physical.Activity..hrs.week."
##  [9] "Medication"                   "Therapy.Type"                
## [11] "Treatment.Start.Date"         "Treatment.Duration..weeks."  
## [13] "Stress.Level..1.10."          "Outcome"                     
## [15] "Treatment.Progress..1.10."    "AI.Detected.Emotional.State" 
## [17] "Adherence.to.Treatment...."

Objetivo

Nosso objetivo é explicar a aderência ao plano de tratamento psicológico (expressa em termos de porcentagem de aderência) por meio das variáveis idade, diagnóstico e severidade dos sintomas.

Estatísticas Descritivas

#Idade
psych::describe(dados$Age) #Descritivas
##    vars   n  mean    sd median trimmed   mad min max range skew kurtosis   se
## X1    1 500 38.71 12.71     38   38.66 16.31  18  60    42 0.04    -1.25 0.57
ggplot(dados, aes(x = Age)) +
  geom_histogram(binwidth = 5, fill = "blue", color = "black", alpha = 0.7) +
  labs(title = "Idade dos Pacientes",
       x = "Idade",
       y = "Número de observações") +
  theme_minimal()

#Diagnóstico
table(dados$Diagnosis) #Descritivas
## 
##          Bipolar Disorder       Generalized Anxiety Major Depressive Disorder 
##                       124                       135                       125 
##            Panic Disorder 
##                       116
ggplot(dados, aes(x = Diagnosis)) +
  geom_bar(fill = "skyblue", color = "black", alpha = 0.8) +
  labs(title = "Diagnósticos dos pacientes",
       x = "Diagnóstico",
       y = "Número de observações") +
  theme_minimal()

# Severidade dos Sintomas
psych::describe(dados$Symptom.Severity..1.10.) #Descritivas
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 500 7.48 1.71      8    7.47 1.48   5  10     5    0    -1.26 0.08
ggplot(dados, aes(x = Symptom.Severity..1.10.)) +
  geom_histogram(binwidth = 1, fill = "red", color = "black", alpha = 0.7) +
  labs(title = "Severidade dos Sintomas (1 - 10)",
       x = "Severidade",
       y = "Número de observações") +
  theme_minimal()

# Aderência ao tratamento
psych::describe(dados$Adherence.to.Treatment....) #Descritivas
##    vars   n  mean   sd median trimmed   mad min max range  skew kurtosis   se
## X1    1 500 75.45 9.09     76   75.53 11.86  60  90    30 -0.05    -1.27 0.41
ggplot(dados, aes(x = Adherence.to.Treatment....)) +
  geom_histogram(binwidth = 5, fill = "green", color = "black", alpha = 0.7) +
  labs(title = "Aderência dos pacientes ao plano de tratamento (%)",
       x = "Aderência",
       y = "Número de observações") +
  theme_minimal()

library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
GGally::ggpairs(dados %>% dplyr::select(Age, Diagnosis, Symptom.Severity..1.10., Adherence.to.Treatment....))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#Gráficos
ggplot(dados, aes(x = Age, y = Adherence.to.Treatment....)) +
  geom_point(color = "cyan", size = 2, alpha = 0.7) +
  labs(title = "Idade vs Aderência",
       x = "Idade",
       y = "Aderência") +
  theme_minimal()

ggplot(dados, aes(x = Symptom.Severity..1.10., y = Adherence.to.Treatment....)) +
  geom_point(color = "red", size = 2, alpha = 0.7) +
  labs(title = "Severidade dos Sintomas vs Aderência",
       x = "Severidade dos Sintomas",
       y = "Aderência") +
  theme_minimal()

ggplot(dados, aes(x = Diagnosis, y = Adherence.to.Treatment....)) +
  geom_boxplot(fill = "skyblue", color = "black", alpha = 0.7) +
  labs(title = "Aderência ao plano de tratamento por categorias diagnósticas",
       x = "Diagnósticos",
       y = "Aderência") +
  theme_minimal()

ggplot(dados, aes(x = Age, y = Symptom.Severity..1.10.)) +
  geom_point(color = "purple", size = 2, alpha = 0.7) +
  labs(title = "Idade vs Severidade dos sintomas",
       x = "Idade",
       y = "Severidade dos sintomas") +
  theme_minimal()

Modelo de Regressão

modelo = lm(Adherence.to.Treatment.... ~ Age + Diagnosis + Symptom.Severity..1.10.,data = dados)

summary(modelo)
## 
## Call:
## lm(formula = Adherence.to.Treatment.... ~ Age + Diagnosis + Symptom.Severity..1.10., 
##     data = dados)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.2393  -8.0342   0.1666   8.2285  15.9944 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        79.00385    2.38420  33.136   <2e-16 ***
## Age                                -0.02052    0.03221  -0.637    0.524    
## DiagnosisGeneralized Anxiety        0.03707    1.13311   0.033    0.974    
## DiagnosisMajor Depressive Disorder -1.13142    1.15465  -0.980    0.328    
## DiagnosisPanic Disorder            -1.25168    1.17846  -1.062    0.289    
## Symptom.Severity..1.10.            -0.29317    0.23951  -1.224    0.222    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.099 on 494 degrees of freedom
## Multiple R-squared:  0.007401,   Adjusted R-squared:  -0.002646 
## F-statistic: 0.7366 on 5 and 494 DF,  p-value: 0.5962

Não foram indetificadas variáveis significativas entre as preditoras para a variável aderência. Além disso, o coeficiente \(R^2\) negativo indica que o modelo não é adequado, podendo gerar resultados inferiores a uma previsão baseada unicamente na média.

Modelo de Regressão 2

Em uma segunda proposta de modelo, tentou-se buscar outras variáveis disponíveis no dataset além daquelas inicialmente previstas. Para isso, foram consideradas as variáveis Gênero, Medicação, Tipo de Terapia, Duração do Tratamento (semanas), Atividade Física (horas por semana), Nível de Stress (1-10), Qualidade do Sono (1-10), Estado Emocional.

Outra medida adotada foi considerar apenas os registros que possuíam progresso no tratamento (1-10) com valores maiores ou iguais a 9, ou seja, tratamentos que estavam se aproximando do seu final. A razão para que essa medida fosse adotada foi descartar registros onde o tratamento recém havia sido iniciado e que, portanto, poderia ainda não ter gerado o resultados para o paciente.

dados_filtrados <- dados %>% filter(Treatment.Progress..1.10.>=9)

modelo = lm(Adherence.to.Treatment.... ~ 1
            + Gender
            + Age
            + Diagnosis
            + Medication
            + Symptom.Severity..1.10.
            + Therapy.Type
            + Treatment.Duration..weeks.
            + Physical.Activity..hrs.week.
            + Mood.Score..1.10.
            + Stress.Level..1.10.
            + Sleep.Quality..1.10.
            + AI.Detected.Emotional.State
            + Therapy.Type*Treatment.Duration..weeks.
            , data = dados_filtrados)

summary(modelo)
## 
## Call:
## lm(formula = Adherence.to.Treatment.... ~ 1 + Gender + Age + 
##     Diagnosis + Medication + Symptom.Severity..1.10. + Therapy.Type + 
##     Treatment.Duration..weeks. + Physical.Activity..hrs.week. + 
##     Mood.Score..1.10. + Stress.Level..1.10. + Sleep.Quality..1.10. + 
##     AI.Detected.Emotional.State + Therapy.Type * Treatment.Duration..weeks., 
##     data = dados_filtrados)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.2086  -5.3389  -0.1505   5.5311  16.4365 
## 
## Coefficients:
##                                                                        Estimate
## (Intercept)                                                            84.63187
## GenderMale                                                             -0.65206
## Age                                                                     0.10998
## DiagnosisGeneralized Anxiety                                            0.99465
## DiagnosisMajor Depressive Disorder                                      1.91494
## DiagnosisPanic Disorder                                                -2.35472
## MedicationAntipsychotics                                               -5.88268
## MedicationAnxiolytics                                                   0.42143
## MedicationBenzodiazepines                                              -3.05947
## MedicationMood Stabilizers                                             -5.14609
## MedicationSSRIs                                                         1.37711
## Symptom.Severity..1.10.                                                 0.31442
## Therapy.TypeDialectical Behavioral Therapy                            -20.29577
## Therapy.TypeInterpersonal Therapy                                      -7.40939
## Therapy.TypeMindfulness-Based Therapy                                 -19.31780
## Treatment.Duration..weeks.                                             -1.43801
## Physical.Activity..hrs.week.                                            0.18477
## Mood.Score..1.10.                                                      -0.01887
## Stress.Level..1.10.                                                    -0.53795
## Sleep.Quality..1.10.                                                    0.64604
## AI.Detected.Emotional.StateDepressed                                    3.26277
## AI.Detected.Emotional.StateExcited                                     -3.30729
## AI.Detected.Emotional.StateHappy                                        1.66599
## AI.Detected.Emotional.StateNeutral                                      1.39657
## AI.Detected.Emotional.StateStressed                                    -0.78855
## Therapy.TypeDialectical Behavioral Therapy:Treatment.Duration..weeks.   1.88129
## Therapy.TypeInterpersonal Therapy:Treatment.Duration..weeks.            1.01453
## Therapy.TypeMindfulness-Based Therapy:Treatment.Duration..weeks.        1.78226
##                                                                       Std. Error
## (Intercept)                                                             12.86277
## GenderMale                                                               1.50177
## Age                                                                      0.05565
## DiagnosisGeneralized Anxiety                                             2.04964
## DiagnosisMajor Depressive Disorder                                       2.04977
## DiagnosisPanic Disorder                                                  2.10682
## MedicationAntipsychotics                                                 2.55159
## MedicationAnxiolytics                                                    2.45031
## MedicationBenzodiazepines                                                2.50158
## MedicationMood Stabilizers                                               2.49885
## MedicationSSRIs                                                          2.60660
## Symptom.Severity..1.10.                                                  0.43970
## Therapy.TypeDialectical Behavioral Therapy                              12.35229
## Therapy.TypeInterpersonal Therapy                                       11.71291
## Therapy.TypeMindfulness-Based Therapy                                   11.63792
## Treatment.Duration..weeks.                                               0.72071
## Physical.Activity..hrs.week.                                             0.24927
## Mood.Score..1.10.                                                        0.41744
## Stress.Level..1.10.                                                      0.41703
## Sleep.Quality..1.10.                                                     0.46775
## AI.Detected.Emotional.StateDepressed                                     2.56883
## AI.Detected.Emotional.StateExcited                                       2.27703
## AI.Detected.Emotional.StateHappy                                         2.44177
## AI.Detected.Emotional.StateNeutral                                       2.41174
## AI.Detected.Emotional.StateStressed                                      2.45665
## Therapy.TypeDialectical Behavioral Therapy:Treatment.Duration..weeks.    0.97172
## Therapy.TypeInterpersonal Therapy:Treatment.Duration..weeks.             0.92761
## Therapy.TypeMindfulness-Based Therapy:Treatment.Duration..weeks.         0.89247
##                                                                       t value
## (Intercept)                                                             6.580
## GenderMale                                                             -0.434
## Age                                                                     1.976
## DiagnosisGeneralized Anxiety                                            0.485
## DiagnosisMajor Depressive Disorder                                      0.934
## DiagnosisPanic Disorder                                                -1.118
## MedicationAntipsychotics                                               -2.305
## MedicationAnxiolytics                                                   0.172
## MedicationBenzodiazepines                                              -1.223
## MedicationMood Stabilizers                                             -2.059
## MedicationSSRIs                                                         0.528
## Symptom.Severity..1.10.                                                 0.715
## Therapy.TypeDialectical Behavioral Therapy                             -1.643
## Therapy.TypeInterpersonal Therapy                                      -0.633
## Therapy.TypeMindfulness-Based Therapy                                  -1.660
## Treatment.Duration..weeks.                                             -1.995
## Physical.Activity..hrs.week.                                            0.741
## Mood.Score..1.10.                                                      -0.045
## Stress.Level..1.10.                                                    -1.290
## Sleep.Quality..1.10.                                                    1.381
## AI.Detected.Emotional.StateDepressed                                    1.270
## AI.Detected.Emotional.StateExcited                                     -1.452
## AI.Detected.Emotional.StateHappy                                        0.682
## AI.Detected.Emotional.StateNeutral                                      0.579
## AI.Detected.Emotional.StateStressed                                    -0.321
## Therapy.TypeDialectical Behavioral Therapy:Treatment.Duration..weeks.   1.936
## Therapy.TypeInterpersonal Therapy:Treatment.Duration..weeks.            1.094
## Therapy.TypeMindfulness-Based Therapy:Treatment.Duration..weeks.        1.997
##                                                                       Pr(>|t|)
## (Intercept)                                                           1.16e-09
## GenderMale                                                              0.6649
## Age                                                                     0.0503
## DiagnosisGeneralized Anxiety                                            0.6283
## DiagnosisMajor Depressive Disorder                                      0.3520
## DiagnosisPanic Disorder                                                 0.2659
## MedicationAntipsychotics                                                0.0228
## MedicationAnxiolytics                                                   0.8637
## MedicationBenzodiazepines                                               0.2236
## MedicationMood Stabilizers                                              0.0415
## MedicationSSRIs                                                         0.5982
## Symptom.Severity..1.10.                                                 0.4759
## Therapy.TypeDialectical Behavioral Therapy                              0.1029
## Therapy.TypeInterpersonal Therapy                                       0.5282
## Therapy.TypeMindfulness-Based Therapy                                   0.0994
## Treatment.Duration..weeks.                                              0.0482
## Physical.Activity..hrs.week.                                            0.4599
## Mood.Score..1.10.                                                       0.9640
## Stress.Level..1.10.                                                     0.1994
## Sleep.Quality..1.10.                                                    0.1697
## AI.Detected.Emotional.StateDepressed                                    0.2064
## AI.Detected.Emotional.StateExcited                                      0.1489
## AI.Detected.Emotional.StateHappy                                        0.4963
## AI.Detected.Emotional.StateNeutral                                      0.5636
## AI.Detected.Emotional.StateStressed                                     0.7488
## Therapy.TypeDialectical Behavioral Therapy:Treatment.Duration..weeks.   0.0551
## Therapy.TypeInterpersonal Therapy:Treatment.Duration..weeks.            0.2762
## Therapy.TypeMindfulness-Based Therapy:Treatment.Duration..weeks.        0.0480
##                                                                          
## (Intercept)                                                           ***
## GenderMale                                                               
## Age                                                                   .  
## DiagnosisGeneralized Anxiety                                             
## DiagnosisMajor Depressive Disorder                                       
## DiagnosisPanic Disorder                                                  
## MedicationAntipsychotics                                              *  
## MedicationAnxiolytics                                                    
## MedicationBenzodiazepines                                                
## MedicationMood Stabilizers                                            *  
## MedicationSSRIs                                                          
## Symptom.Severity..1.10.                                                  
## Therapy.TypeDialectical Behavioral Therapy                               
## Therapy.TypeInterpersonal Therapy                                        
## Therapy.TypeMindfulness-Based Therapy                                 .  
## Treatment.Duration..weeks.                                            *  
## Physical.Activity..hrs.week.                                             
## Mood.Score..1.10.                                                        
## Stress.Level..1.10.                                                      
## Sleep.Quality..1.10.                                                     
## AI.Detected.Emotional.StateDepressed                                     
## AI.Detected.Emotional.StateExcited                                       
## AI.Detected.Emotional.StateHappy                                         
## AI.Detected.Emotional.StateNeutral                                       
## AI.Detected.Emotional.StateStressed                                      
## Therapy.TypeDialectical Behavioral Therapy:Treatment.Duration..weeks. .  
## Therapy.TypeInterpersonal Therapy:Treatment.Duration..weeks.             
## Therapy.TypeMindfulness-Based Therapy:Treatment.Duration..weeks.      *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.168 on 125 degrees of freedom
## Multiple R-squared:  0.2746, Adjusted R-squared:  0.1179 
## F-statistic: 1.752 on 27 and 125 DF,  p-value: 0.02089
library(GGally)

GGally::ggpairs(dados_filtrados %>% dplyr::select(Gender, Age, Diagnosis, Symptom.Severity..1.10., Therapy.Type, Treatment.Duration..weeks., Treatment.Progress..1.10., Adherence.to.Treatment....))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Seleção de Modelos

Antes de prosseguir com a execução dos algoritmos de seleção de modelos forward e stepwise, conjunto de dados foi dividido em conjuntos de treinamento (80%) e teste (20%).

# Dividir os dados manualmente em treino (80%) e teste (20%)
set.seed(42) # Para reprodutibilidade
indices_treino <- sample(1:nrow(dados_filtrados), size = 0.8 * nrow(dados_filtrados))
treino <- dados[indices_treino, ]
teste <- dados[-indices_treino, ]

Método Forward

Nesse método o modelo começa com nenhuma covariável, a cada passo o algoritmo decide se determinada preditora será adicionada ao modelo.

min_model <- lm(Adherence.to.Treatment.... ~ 1, data = dados_filtrados)

reg_forward <- step(
  object = min_model,
  direction = "forward",
  scope = formula(modelo),
  k = 2
)
## Start:  AIC=662.84
## Adherence.to.Treatment.... ~ 1
## 
##                                Df Sum of Sq   RSS    AIC
## + Therapy.Type                  3    578.83 10916 660.93
## + Age                           1    187.56 11307 662.32
## + Treatment.Duration..weeks.    1    183.52 11311 662.38
## + Stress.Level..1.10.           1    155.20 11340 662.76
## <none>                                      11495 662.84
## + AI.Detected.Emotional.State   5    674.40 10820 663.59
## + Gender                        1     12.48 11482 664.67
## + Medication                    5    596.47 10898 664.69
## + Sleep.Quality..1.10.          1      6.41 11488 664.75
## + Physical.Activity..hrs.week.  1      5.18 11490 664.77
## + Symptom.Severity..1.10.       1      1.61 11493 664.82
## + Mood.Score..1.10.             1      0.56 11494 664.83
## + Diagnosis                     3    236.05 11259 665.67
## 
## Step:  AIC=660.93
## Adherence.to.Treatment.... ~ Therapy.Type
## 
##                                Df Sum of Sq   RSS    AIC
## + Medication                    5    799.64 10116 659.30
## + Age                           1    211.12 10705 659.95
## <none>                                      10916 660.93
## + Stress.Level..1.10.           1    122.25 10794 661.21
## + Treatment.Duration..weeks.    1     57.97 10858 662.12
## + Gender                        1     43.59 10872 662.32
## + Sleep.Quality..1.10.          1     22.63 10893 662.62
## + Physical.Activity..hrs.week.  1     17.70 10898 662.69
## + Symptom.Severity..1.10.       1     10.19 10906 662.79
## + Mood.Score..1.10.             1      5.78 10910 662.85
## + AI.Detected.Emotional.State   5    540.88 10375 663.16
## + Diagnosis                     3    194.92 10721 664.18
## 
## Step:  AIC=659.3
## Adherence.to.Treatment.... ~ Therapy.Type + Medication
## 
##                                Df Sum of Sq     RSS    AIC
## + Age                           1    231.10  9885.3 657.76
## + Stress.Level..1.10.           1    139.30  9977.1 659.17
## <none>                                      10116.4 659.30
## + Sleep.Quality..1.10.          1     87.03 10029.3 659.97
## + Physical.Activity..hrs.week.  1     69.65 10046.7 660.24
## + Treatment.Duration..weeks.    1     68.37 10048.0 660.26
## + Mood.Score..1.10.             1     43.79 10072.6 660.63
## + Gender                        1     18.94 10097.4 661.01
## + AI.Detected.Emotional.State   5    526.44  9589.9 661.12
## + Symptom.Severity..1.10.       1      4.13 10112.2 661.23
## + Diagnosis                     3    230.99  9885.4 661.76
## 
## Step:  AIC=657.76
## Adherence.to.Treatment.... ~ Therapy.Type + Medication + Age
## 
##                                Df Sum of Sq    RSS    AIC
## + Stress.Level..1.10.           1    129.31 9756.0 657.74
## <none>                                      9885.3 657.76
## + Sleep.Quality..1.10.          1    118.40 9766.9 657.92
## + Physical.Activity..hrs.week.  1     71.64 9813.6 658.65
## + Treatment.Duration..weeks.    1     46.17 9839.1 659.04
## + Mood.Score..1.10.             1     33.93 9851.3 659.23
## + Symptom.Severity..1.10.       1     14.33 9870.9 659.54
## + Gender                        1      9.50 9875.8 659.61
## + Diagnosis                     3    253.81 9631.5 659.78
## + AI.Detected.Emotional.State   5    499.60 9385.7 659.82
## 
## Step:  AIC=657.74
## Adherence.to.Treatment.... ~ Therapy.Type + Medication + Age + 
##     Stress.Level..1.10.
## 
##                                Df Sum of Sq    RSS    AIC
## <none>                                      9756.0 657.74
## + Sleep.Quality..1.10.          1    112.78 9643.2 657.97
## + Physical.Activity..hrs.week.  1     85.15 9670.8 658.40
## + Treatment.Duration..weeks.    1     41.82 9714.1 659.09
## + Symptom.Severity..1.10.       1     22.10 9733.9 659.40
## + Mood.Score..1.10.             1     21.08 9734.9 659.41
## + Gender                        1     14.37 9741.6 659.52
## + Diagnosis                     3    254.72 9501.2 659.70
## + AI.Detected.Emotional.State   5    469.51 9286.5 660.20
summary(reg_forward)
## 
## Call:
## lm(formula = Adherence.to.Treatment.... ~ Therapy.Type + Medication + 
##     Age + Stress.Level..1.10., data = dados_filtrados)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -14.456  -6.389   1.129   6.133  16.299 
## 
## Coefficients:
##                                            Estimate Std. Error t value Pr(>|t|)
## (Intercept)                                73.41723    4.48844  16.357  < 2e-16
## Therapy.TypeDialectical Behavioral Therapy  4.83107    1.90547   2.535  0.01232
## Therapy.TypeInterpersonal Therapy           6.33640    1.97653   3.206  0.00166
## Therapy.TypeMindfulness-Based Therapy       3.74758    2.01184   1.863  0.06456
## MedicationAntipsychotics                   -5.24587    2.43697  -2.153  0.03304
## MedicationAnxiolytics                       0.45141    2.41564   0.187  0.85203
## MedicationBenzodiazepines                  -2.21933    2.41357  -0.920  0.35938
## MedicationMood Stabilizers                 -4.36657    2.40067  -1.819  0.07103
## MedicationSSRIs                             0.88583    2.45481   0.361  0.71874
## Age                                         0.09742    0.05430   1.794  0.07495
## Stress.Level..1.10.                        -0.55704    0.40603  -1.372  0.17225
##                                               
## (Intercept)                                ***
## Therapy.TypeDialectical Behavioral Therapy *  
## Therapy.TypeInterpersonal Therapy          ** 
## Therapy.TypeMindfulness-Based Therapy      .  
## MedicationAntipsychotics                   *  
## MedicationAnxiolytics                         
## MedicationBenzodiazepines                     
## MedicationMood Stabilizers                 .  
## MedicationSSRIs                               
## Age                                        .  
## Stress.Level..1.10.                           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.289 on 142 degrees of freedom
## Multiple R-squared:  0.1513, Adjusted R-squared:  0.09151 
## F-statistic: 2.531 on 10 and 142 DF,  p-value: 0.007779
# predição na amostra de teste
preditoras_selecionadas_forward <- c(names(reg_forward$model))
predicao_forward_amostra_teste <- predict(reg_forward, newdata = data.frame(1, teste[,preditoras_selecionadas_forward]))

# medida quadrática do erro de predição
erro_forward <- mean((teste[,'Adherence.to.Treatment....'] - predicao_forward_amostra_teste)^2)

print(paste('RMSE (forward):', erro_forward))
## [1] "RMSE (forward): 94.4471769457305"

Método Stepwise

max_model <- modelo

reg_stepwise <- step(
  object = max_model,
  direction = "both",
  k = 2
)
## Start:  AIC=667.73
## Adherence.to.Treatment.... ~ 1 + Gender + Age + Diagnosis + Medication + 
##     Symptom.Severity..1.10. + Therapy.Type + Treatment.Duration..weeks. + 
##     Physical.Activity..hrs.week. + Mood.Score..1.10. + Stress.Level..1.10. + 
##     Sleep.Quality..1.10. + AI.Detected.Emotional.State + Therapy.Type * 
##     Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - Mood.Score..1.10.                        1      0.14 8338.9 665.73
## - Gender                                   1     12.58 8351.4 665.96
## - Symptom.Severity..1.10.                  1     34.11 8372.9 666.35
## - Physical.Activity..hrs.week.             1     36.65 8375.4 666.40
## <none>                                                 8338.8 667.73
## - Stress.Level..1.10.                      1    111.01 8449.8 667.75
## - Therapy.Type:Treatment.Duration..weeks.  3    344.43 8683.2 667.92
## - Sleep.Quality..1.10.                     1    127.26 8466.0 668.05
## - Diagnosis                                3    370.83 8709.6 668.39
## - AI.Detected.Emotional.State              5    605.42 8944.2 668.45
## - Age                                      1    260.60 8599.4 670.44
## - Medication                               5    986.10 9324.9 674.83
## 
## Step:  AIC=665.73
## Adherence.to.Treatment.... ~ Gender + Age + Diagnosis + Medication + 
##     Symptom.Severity..1.10. + Therapy.Type + Treatment.Duration..weeks. + 
##     Physical.Activity..hrs.week. + Stress.Level..1.10. + Sleep.Quality..1.10. + 
##     AI.Detected.Emotional.State + Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - Gender                                   1     12.46 8351.4 663.96
## - Symptom.Severity..1.10.                  1     34.04 8373.0 664.36
## - Physical.Activity..hrs.week.             1     37.36 8376.3 664.42
## <none>                                                 8338.9 665.73
## - Stress.Level..1.10.                      1    112.39 8451.3 665.78
## - Therapy.Type:Treatment.Duration..weeks.  3    345.08 8684.0 665.94
## - Sleep.Quality..1.10.                     1    127.47 8466.4 666.05
## - AI.Detected.Emotional.State              5    605.62 8944.5 666.46
## - Diagnosis                                3    375.46 8714.4 666.47
## + Mood.Score..1.10.                        1      0.14 8338.8 667.73
## - Age                                      1    260.50 8599.4 668.44
## - Medication                               5   1003.19 9342.1 673.11
## 
## Step:  AIC=663.96
## Adherence.to.Treatment.... ~ Age + Diagnosis + Medication + Symptom.Severity..1.10. + 
##     Therapy.Type + Treatment.Duration..weeks. + Physical.Activity..hrs.week. + 
##     Stress.Level..1.10. + Sleep.Quality..1.10. + AI.Detected.Emotional.State + 
##     Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - Symptom.Severity..1.10.                  1     35.51 8386.9 662.61
## - Physical.Activity..hrs.week.             1     43.08 8394.5 662.75
## - Stress.Level..1.10.                      1    109.04 8460.4 663.95
## <none>                                                 8351.4 663.96
## - Therapy.Type:Treatment.Duration..weeks.  3    334.42 8685.8 663.97
## - Sleep.Quality..1.10.                     1    141.45 8492.8 664.53
## - Diagnosis                                3    369.52 8720.9 664.58
## - AI.Detected.Emotional.State              5    605.70 8957.1 664.67
## + Gender                                   1     12.46 8338.9 665.73
## + Mood.Score..1.10.                        1      0.02 8351.4 665.96
## - Age                                      1    271.47 8622.8 666.86
## - Medication                               5   1044.09 9395.5 671.98
## 
## Step:  AIC=662.61
## Adherence.to.Treatment.... ~ Age + Diagnosis + Medication + Therapy.Type + 
##     Treatment.Duration..weeks. + Physical.Activity..hrs.week. + 
##     Stress.Level..1.10. + Sleep.Quality..1.10. + AI.Detected.Emotional.State + 
##     Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - Physical.Activity..hrs.week.             1     51.92 8438.8 661.55
## - Stress.Level..1.10.                      1     98.73 8485.6 662.40
## - Therapy.Type:Treatment.Duration..weeks.  3    331.68 8718.6 662.54
## <none>                                                 8386.9 662.61
## - Diagnosis                                3    349.41 8736.3 662.85
## - Sleep.Quality..1.10.                     1    124.69 8511.6 662.87
## - AI.Detected.Emotional.State              5    614.70 9001.6 663.43
## + Symptom.Severity..1.10.                  1     35.51 8351.4 663.96
## + Gender                                   1     13.92 8373.0 664.36
## + Mood.Score..1.10.                        1      0.62 8386.3 664.60
## - Age                                      1    250.08 8637.0 665.11
## - Medication                               5   1051.75 9438.6 670.69
## 
## Step:  AIC=661.55
## Adherence.to.Treatment.... ~ Age + Diagnosis + Medication + Therapy.Type + 
##     Treatment.Duration..weeks. + Stress.Level..1.10. + Sleep.Quality..1.10. + 
##     AI.Detected.Emotional.State + Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - Stress.Level..1.10.                      1     87.08 8525.9 661.13
## - Diagnosis                                3    324.87 8763.7 661.33
## - Therapy.Type:Treatment.Duration..weeks.  3    331.52 8770.3 661.45
## <none>                                                 8438.8 661.55
## - Sleep.Quality..1.10.                     1    141.44 8580.2 662.10
## + Physical.Activity..hrs.week.             1     51.92 8386.9 662.61
## + Symptom.Severity..1.10.                  1     44.36 8394.5 662.75
## - AI.Detected.Emotional.State              5    657.69 9096.5 663.04
## + Gender                                   1     20.84 8418.0 663.18
## + Mood.Score..1.10.                        1      6.00 8432.8 663.45
## - Age                                      1    248.22 8687.0 663.99
## - Medication                               5   1016.87 9455.7 668.96
## 
## Step:  AIC=661.13
## Adherence.to.Treatment.... ~ Age + Diagnosis + Medication + Therapy.Type + 
##     Treatment.Duration..weeks. + Sleep.Quality..1.10. + AI.Detected.Emotional.State + 
##     Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - Diagnosis                                3    327.96 8853.9 660.90
## - Therapy.Type:Treatment.Duration..weeks.  3    340.18 8866.1 661.11
## <none>                                                 8525.9 661.13
## + Stress.Level..1.10.                      1     87.08 8438.8 661.55
## - Sleep.Quality..1.10.                     1    139.69 8665.6 661.61
## + Physical.Activity..hrs.week.             1     40.28 8485.6 662.40
## + Symptom.Severity..1.10.                  1     32.33 8493.6 662.54
## + Gender                                   1     15.79 8510.1 662.84
## - AI.Detected.Emotional.State              5    679.05 9204.9 662.85
## + Mood.Score..1.10.                        1     11.92 8514.0 662.91
## - Age                                      1    261.04 8786.9 663.74
## - Medication                               5    990.51 9516.4 667.94
## 
## Step:  AIC=660.9
## Adherence.to.Treatment.... ~ Age + Medication + Therapy.Type + 
##     Treatment.Duration..weeks. + Sleep.Quality..1.10. + AI.Detected.Emotional.State + 
##     Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq    RSS    AIC
## - AI.Detected.Emotional.State              5    597.03 9450.9 660.88
## <none>                                                 8853.9 660.90
## - Therapy.Type:Treatment.Duration..weeks.  3    364.51 9218.4 661.07
## + Diagnosis                                3    327.96 8525.9 661.13
## - Sleep.Quality..1.10.                     1    133.74 8987.6 661.19
## + Stress.Level..1.10.                      1     90.18 8763.7 661.33
## + Physical.Activity..hrs.week.             1     19.11 8834.8 662.57
## + Symptom.Severity..1.10.                  1     12.31 8841.6 662.69
## + Gender                                   1      7.09 8846.8 662.78
## + Mood.Score..1.10.                        1      1.04 8852.8 662.88
## - Age                                      1    242.91 9096.8 663.04
## - Medication                               5    923.26 9777.1 666.08
## 
## Step:  AIC=660.88
## Adherence.to.Treatment.... ~ Age + Medication + Therapy.Type + 
##     Treatment.Duration..weeks. + Sleep.Quality..1.10. + Therapy.Type:Treatment.Duration..weeks.
## 
##                                           Df Sum of Sq     RSS    AIC
## - Therapy.Type:Treatment.Duration..weeks.  3    274.46  9725.3 659.26
## - Sleep.Quality..1.10.                     1     97.23  9548.1 660.45
## <none>                                                  9450.9 660.88
## + AI.Detected.Emotional.State              5    597.03  8853.9 660.90
## + Stress.Level..1.10.                      1    109.04  9341.8 661.11
## + Physical.Activity..hrs.week.             1     48.39  9402.5 662.10
## + Symptom.Severity..1.10.                  1     22.74  9428.1 662.52
## + Mood.Score..1.10.                        1      9.22  9441.7 662.73
## + Gender                                   1      7.83  9443.1 662.76
## + Diagnosis                                3    245.94  9204.9 662.85
## - Age                                      1    257.09  9708.0 662.99
## - Medication                               5    900.19 10351.1 664.80
## 
## Step:  AIC=659.26
## Adherence.to.Treatment.... ~ Age + Medication + Therapy.Type + 
##     Treatment.Duration..weeks. + Sleep.Quality..1.10.
## 
##                                           Df Sum of Sq     RSS    AIC
## - Treatment.Duration..weeks.               1     41.53  9766.9 657.92
## - Sleep.Quality..1.10.                     1    113.76  9839.1 659.04
## <none>                                                  9725.3 659.26
## + Stress.Level..1.10.                      1    119.76  9605.6 659.37
## + Physical.Activity..hrs.week.             1     45.30  9680.0 660.55
## + Therapy.Type:Treatment.Duration..weeks.  3    274.46  9450.9 660.88
## + Symptom.Severity..1.10.                  1     21.32  9704.0 660.93
## - Age                                      1    239.02  9964.4 660.98
## + Diagnosis                                3    264.56  9460.8 661.04
## + Mood.Score..1.10.                        1     12.44  9712.9 661.07
## + AI.Detected.Emotional.State              5    506.97  9218.4 661.07
## + Gender                                   1      1.11  9724.2 661.25
## - Medication                               5    908.96 10634.3 662.93
## - Therapy.Type                             3    730.00 10455.3 664.34
## 
## Step:  AIC=657.92
## Adherence.to.Treatment.... ~ Age + Medication + Therapy.Type + 
##     Sleep.Quality..1.10.
## 
##                                Df Sum of Sq     RSS    AIC
## - Sleep.Quality..1.10.          1    118.40  9885.3 657.76
## <none>                                       9766.9 657.92
## + Stress.Level..1.10.           1    123.70  9643.2 657.97
## + Physical.Activity..hrs.week.  1     50.36  9716.5 659.13
## + Treatment.Duration..weeks.    1     41.53  9725.3 659.26
## + Symptom.Severity..1.10.       1     24.43  9742.4 659.53
## + AI.Detected.Emotional.State   5    516.41  9250.5 659.60
## + Mood.Score..1.10.             1     19.59  9747.3 659.61
## + Diagnosis                     3    262.75  9504.1 659.74
## + Gender                        1      3.02  9763.9 659.87
## - Age                           1    262.47 10029.3 659.97
## - Medication                    5    903.71 10670.6 661.46
## - Therapy.Type                  3    874.44 10641.3 665.04
## 
## Step:  AIC=657.76
## Adherence.to.Treatment.... ~ Age + Medication + Therapy.Type
## 
##                                Df Sum of Sq     RSS    AIC
## + Stress.Level..1.10.           1    129.31  9756.0 657.74
## <none>                                       9885.3 657.76
## + Sleep.Quality..1.10.          1    118.40  9766.9 657.92
## + Physical.Activity..hrs.week.  1     71.64  9813.6 658.65
## + Treatment.Duration..weeks.    1     46.17  9839.1 659.04
## + Mood.Score..1.10.             1     33.93  9851.3 659.23
## - Age                           1    231.10 10116.4 659.30
## + Symptom.Severity..1.10.       1     14.33  9870.9 659.54
## + Gender                        1      9.50  9875.8 659.61
## + Diagnosis                     3    253.81  9631.5 659.78
## + AI.Detected.Emotional.State   5    499.60  9385.7 659.82
## - Medication                    5    819.62 10704.9 659.95
## - Therapy.Type                  3    812.54 10697.8 663.85
## 
## Step:  AIC=657.74
## Adherence.to.Treatment.... ~ Age + Medication + Therapy.Type + 
##     Stress.Level..1.10.
## 
##                                Df Sum of Sq     RSS    AIC
## <none>                                       9756.0 657.74
## - Stress.Level..1.10.           1    129.31  9885.3 657.76
## + Sleep.Quality..1.10.          1    112.78  9643.2 657.97
## + Physical.Activity..hrs.week.  1     85.15  9670.8 658.40
## + Treatment.Duration..weeks.    1     41.82  9714.1 659.09
## - Age                           1    221.11  9977.1 659.17
## + Symptom.Severity..1.10.       1     22.10  9733.9 659.40
## + Mood.Score..1.10.             1     21.08  9734.9 659.41
## + Gender                        1     14.37  9741.6 659.52
## + Diagnosis                     3    254.72  9501.2 659.70
## + AI.Detected.Emotional.State   5    469.51  9286.5 660.20
## - Medication                    5    841.34 10597.3 660.40
## - Therapy.Type                  3    774.02 10530.0 663.43
summary(reg_stepwise)
## 
## Call:
## lm(formula = Adherence.to.Treatment.... ~ Age + Medication + 
##     Therapy.Type + Stress.Level..1.10., data = dados_filtrados)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -14.456  -6.389   1.129   6.133  16.299 
## 
## Coefficients:
##                                            Estimate Std. Error t value Pr(>|t|)
## (Intercept)                                73.41723    4.48844  16.357  < 2e-16
## Age                                         0.09742    0.05430   1.794  0.07495
## MedicationAntipsychotics                   -5.24587    2.43697  -2.153  0.03304
## MedicationAnxiolytics                       0.45141    2.41564   0.187  0.85203
## MedicationBenzodiazepines                  -2.21933    2.41357  -0.920  0.35938
## MedicationMood Stabilizers                 -4.36657    2.40067  -1.819  0.07103
## MedicationSSRIs                             0.88583    2.45481   0.361  0.71874
## Therapy.TypeDialectical Behavioral Therapy  4.83107    1.90547   2.535  0.01232
## Therapy.TypeInterpersonal Therapy           6.33640    1.97653   3.206  0.00166
## Therapy.TypeMindfulness-Based Therapy       3.74758    2.01184   1.863  0.06456
## Stress.Level..1.10.                        -0.55704    0.40603  -1.372  0.17225
##                                               
## (Intercept)                                ***
## Age                                        .  
## MedicationAntipsychotics                   *  
## MedicationAnxiolytics                         
## MedicationBenzodiazepines                     
## MedicationMood Stabilizers                 .  
## MedicationSSRIs                               
## Therapy.TypeDialectical Behavioral Therapy *  
## Therapy.TypeInterpersonal Therapy          ** 
## Therapy.TypeMindfulness-Based Therapy      .  
## Stress.Level..1.10.                           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.289 on 142 degrees of freedom
## Multiple R-squared:  0.1513, Adjusted R-squared:  0.09151 
## F-statistic: 2.531 on 10 and 142 DF,  p-value: 0.007779
# predição na amostra de teste
preditoras_selecionadas_stepwise <- c(names(reg_stepwise$model))
predicao_stepwise_amostra_teste <- predict(reg_stepwise, newdata = data.frame(1, teste[,preditoras_selecionadas_stepwise]))

# medida quadrática do erro de predição
erro_stepwise <- mean((teste[,'Adherence.to.Treatment....'] - predicao_stepwise_amostra_teste)^2)

print(paste('RMSE (forward):', erro_stepwise))
## [1] "RMSE (forward): 94.4471769457305"

Multicolinearidade

# Deste ponto em diante, o modelo atribuído a model será utilizado
model <- reg_stepwise

Para avaliarmos se há presença de multicolinearidade, iremos utilizar os gráficos abaixo, que nos mostram a correlação entre as nossas variáveis preditoras contínuas e o fator de inflação de variância (VIF).

VIF
GVIF Df GVIF^(1/(2*Df))
Age 1.023217 1 1.011542
Medication 1.171066 5 1.015917
Therapy.Type 1.144504 3 1.022750
Stress.Level..1.10. 1.054611 1 1.026943

Assim, percebemos que parece não haver multicolinearidade entre as covariáveis, podendo-se ver isso através do corplot que nos mostra as correlações. Também percebemos pelo VIF que a variância dos estimadores não está sendo inflada pela aparição das outras covariáveis, pois os valores resultaram entre 1 e 2. Portanto, com os índicios acima podemos concluir que não há presença de multicolinearidade entre as variáveis preditoras.

Análise de Resíduos

Normalidade

Para avaliarmos a normalidade, utilizaremos o histograma, o qqplot e alguns testes de normalidade como seguem.

ggplot(mapping = aes(x = model$residuals)) + geom_histogram() + xlab("Residuals") + ylab(" ")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

autoplot(model, which = 2, label.size = 3)

library(kableExtra)
library(nortest)
norm.test.stat = c(shapiro.test(model$residuals)$statistic, 
                   ks.test(model$residuals, "pnorm")$statistic, 
                   ad.test(model$residuals)$statistic, 
                   cvm.test(model$residuals)$statistic)
## Warning in ks.test.default(model$residuals, "pnorm"): ties should not be
## present for the Kolmogorov-Smirnov test
norm.test.pvalue = c(shapiro.test(model$residuals)$p.value, 
                   ks.test(model$residuals, "pnorm")$p.value, 
                   ad.test(model$residuals)$p.value, 
                   cvm.test(model$residuals)$p.value)
## Warning in ks.test.default(model$residuals, "pnorm"): ties should not be
## present for the Kolmogorov-Smirnov test
norm.test = cbind(norm.test.stat, norm.test.pvalue)

rownames(norm.test) = c("Shapiro-Wilk", "Kolmogorov-Smirnov", 
                        "Anderson-Darling", "Cramer-Von-Mises")
colnames(norm.test) = c("Statistic", "P.value")

kable(norm.test, caption = "Testes de normalidade")
Testes de normalidade
Statistic P.value
Shapiro-Wilk 0.9707613 0.0024225
Kolmogorov-Smirnov 0.4137537 0.0000000
Anderson-Darling 1.0183027 0.0107875
Cramer-Von-Mises 0.1493265 0.0239703

Primeiramente, percebemos através do histograma um comportamento não normal, onde os valores da distribuição se alternam, a causa da esquerda parece mais pesada e a cauda da direita se estendendo, sendo, portanto, mais longa. Pelo qqplot percebemos uma tendência dos dados de se afastarem da reta nas pontas do gráfico mesmo que os dados estejam concentrados de forma a seguir a reta no centro. Já os testes de normalidade rejeitam a normalidade, pois seus p-valores foram muito pequenos. Sendo assim, podemos concluir com as evidências acima que os resíduos não são normalmente distribuídos.

Homoscedasticidade:

Agora, para avaliarmos a homoscedasticidade, utilizaremos o gráfico dos Resíduo \(\times\) Valores ajustados e o teste de homocedasticidade de Breusch-Pagan.

Teste de homocedasticidade
Statistic P.value
Breusch-Pagan 5.36934 0.8651808

Pelo gráfico percebemos que o comportamento dos resíduos não parece ser aleatório, pois parece seguir um padrão parecido com uma curva, o que é um índicio de heteroscedasticidade. Esse comportamento, também pode indicar a ausência de alguma covariável que seja importante para explicar a variável dependente.

Pelo teste de Breusch-Pagan aceitamos a hipótese nula de homoscedasticidade, com um p-valor de 0.8652. Dessa forma, dada as evidências acima, podemos dizer que os resíduos são homoscedásticos.

Pontos Influentes e Outliers

Outliers

Para identificar se há presença de outliers podemos utilizar os resíduos estudentizados e padronizados.

Resíduos padronizados ajudam a identificar observações que são outliers.

# Calcular resíduos padronizados
residuos_padronizados <- rstandard(model)

# Identificar observações problemáticas
outliers <- which(abs(residuos_padronizados) > 1.82)
outliers
##  50  62 148 
##  50  62 148
autoplot(model, 1:4, label.size = 3)

Pontos de Alavanca

Pontos de alavanca indicam observações com valores incomuns de covariáveis. Para avaliar a presença de pontos de alavanca, podemos utilizar o valor \(h_{ii}\) associado à matriz de projeção, também o gráfico de resíduos vs leverage.

# Calcular leverage
leverage <- hatvalues(model)

# Critério para leverage alto
n <- nrow(dados %>% filter(Treatment.Progress..1.10.>=9))
k <- length(coef(model)) - 1
cutoff_leverage <- 2 * (k + 1) / n 
cutoff_leverage
## [1] 0.1437908
# Identificar pontos de alavanca
pontos_alavanca <- which(leverage > cutoff_leverage)
pontos_alavanca
## named integer(0)
length(pontos_alavanca)
## [1] 0
hat_valores <- hatvalues(model)
df <- data.frame(
  obs = seq_along(hat_valores),
  hat = hat_valores
)

limite <- 2 * mean(hat_valores)
limite
## [1] 0.1437908
ggplot(df, aes(x = obs, y = hat)) +
  geom_bar(stat = "identity", fill = "darkcyan", alpha = 0.8) +
  geom_hline(yintercept = limite, color = "red", linetype = "dashed") +
  theme_minimal() +
  labs(title = "Valores de Alavancagem (Hat Values)",
       x = "Índice da Observação",
       y = "Leverage")

ggplot(df, aes(x = obs, y = hat)) +
  geom_point(size = 3, color = "blue") +
  geom_hline(yintercept = limite, color = "red", linetype = "dashed") +
  # Adicionando rótulos condicionalmente
  geom_text(
    aes(label = ifelse(hat > limite, obs, "")),  # só mostra obs se hat>limite
    vjust = -0.5,   # ajusta a posição vertical do texto
    color = "red"
  ) +
  theme_minimal() +
  labs(
    title = "Gráfico de Alavancagem (Hat Values) com rótulos de outliers",
    x = "Índice da Observação",
    y = "Leverage (Hat Values)"
  )

Como podemos perceber, considerando esse limite como indicador de alavancagem, a quantidade de observações é muito grande, totalizando 52 observações.

Quando analisamos o gráfico acima, percebemos que há a presença também de pontos de alavanca e estes são as observações 5, 37 e 56.

Pontos Influentes

A distância de Cook identifica observações influentes. Entre alguns dos critérios para considerar um ponto influente:

  • \(D_i>1\)
  • \(D_i > 4/n\)
cooks_distance <- cooks.distance(model)

n <- nrow(dados %>% filter(Treatment.Progress..1.10.>=9))

# Identificar observações com distância de Cook > 1
which(cooks_distance > 1)
## named integer(0)
which(cooks_distance > 4/n)
##  23  92 148 
##  23  92 148
length(which(cooks_distance > 4/n))
## [1] 3

Considerando o segundo critério há 3 observações influentes.

Considerando o gráfico acima, há 3 obsrvações influentes, são elas 23, 92 e 148 os pontos influentes.

(medv) com as variáveis lstat (percentual de moradores de baixa renda) e rm (número médio de cômodos por residência)

kable(dados_filtrados[c(23, 92, 48),])
Patient.ID Age Gender Diagnosis Symptom.Severity..1.10. Mood.Score..1.10. Sleep.Quality..1.10. Physical.Activity..hrs.week. Medication Therapy.Type Treatment.Start.Date Treatment.Duration..weeks. Stress.Level..1.10. Outcome Treatment.Progress..1.10. AI.Detected.Emotional.State Adherence.to.Treatment….
23 72 57 Male Major Depressive Disorder 5 4 5 3 Antipsychotics Mindfulness-Based Therapy 2024-02-25 13 5 No Change 10 Excited 61
92 291 54 Male Panic Disorder 7 6 7 3 Anxiolytics Cognitive Behavioral Therapy 2024-02-08 14 5 No Change 10 Excited 62
48 146 29 Male Panic Disorder 10 6 4 3 SSRIs Cognitive Behavioral Therapy 2024-03-28 13 8 Deteriorated 10 Anxious 78

Conclusão

Neste trabalho foram analisados os fatores que influenciam na aderência ao tratamento psicológico, com base em um banco de dados com base em um banco de dados contendo registros de 500 pacientes. Inicialmente, foi realizado um modelo de regressão linear considerando as variáveis idade, diagnóstico e severidade dos sintomas. Contudo, os resultados indicaram uma baixa adequação do modelo, com coeficientes de regressão não significativos e um coeficiente \(Rˆ2\) ajustado próximo de zero, sugerindo que essas variáveis isoladas não explicavam de forma satisfatória a variabilidade na aderência.

Para aprimorar o modelo, foi feita uma seleção de novas variáveis preditoras e aplicação de métodos de seleção de modelos como forward e stepwise. Essas abordagens identificaram variáveis adicionais relevantes, incluindo tipo de terapia, duração do tratamento e medicação. Apesar de uma melhora nos valores de \(Rˆ2\) ajustado, o modelo continuou apresentando limitações, como resíduos não normalmente distribuídos. A análise de influências identificou algumas observações problemáticas, sugerindo que fatores externos ou dados extremos podem estar impactando os resultados.

Concluímos que, embora os modelos lineares tenham oferecido insights valiosos, há limitações importantes para prever a aderência ao tratamento psicológico exclusivamente com as variáveis analisadas. Recomenda-se considerar métodos mais robustos, como modelos não lineares ou machine learning, que possam capturar melhor as relações complexas entre as variáveis. Além disso, uma maior atenção à qualidade dos dados e entendimento das variáveis pode ajudar a construir modelos mais eficazes.